'use strict';

module.exports = app => {
    const {STRING, JSON, TEXT, INTEGER, DATE, NOW} = app.Sequelize;

    const Weibo = app.model.define('weibo', {
        id: {
            type: INTEGER,
            primaryKey: true,
            autoIncrement: true,
        },
        idstr: STRING(255),
        res_data: JSON,
        content: TEXT,
        send_content: STRING(255),
        user_name: STRING(255),
        user_idstr: STRING(255),
        createAt: {
            type: DATE,
            // 可以重写某个字段的字段名
            field: 'created_at',
            allowNull: false,
            defaultValue: NOW,
        },
        updateAt: {
            type: DATE,
            field: 'updated_at',
            allowNull: false,
            defaultValue: NOW,
        },
    }, {
        timestamps: false,
        freezeTableName: true,
        tableName: 'weibos',
        underscored: true,
    });


    Weibo.findByIdWithUser = async function (idstr) {
        return await this.findOne({
            where: {idstr: idstr},
        });
    };

    return Weibo;
};
